package group2assignone.view.manager;

import group2assignone.func.UCCtoALAdapter;
import group2assignone.model.Manager;
import group2assignone.ucm.UCLogout;
import group2assignone.ucm.manager.*;
import group2assignone.view.OurView;
import java.awt.*;
import javax.swing.*;

/**
 * manager view
 * @author group2
 */
public class ManagerView extends OurView {

    static private ManagerView instance;
    private JButton createFlight = new JButton("Create Flight");
    private JButton editFlight = new JButton("Edit Flight");
    private JButton addPromotion = new JButton("Add Promotion");
    private JButton editGST = new JButton("Edit GST");
    private JButton deleteFlight = new JButton("Delete Flight");
    private JButton addAirport = new JButton("Add Airport");
    private JButton editAirport = new JButton("Edit Airport");
    private JButton deleteAirport = new JButton("Delete Airport");
    private JButton viewUsers = new JButton("View Users");
    private JButton logout = new JButton("Logout");
    private JButton salesReport = new JButton("Sales Report");
    private JLabel welcome = new JLabel();
    private Manager man;

    private ManagerView()
    {
            setActionListeners();
    }

    public static ManagerView getInstance() {
        if (instance == null) {
            instance = new ManagerView();
        }
        return instance;
    }

    public void setManager(Manager man){
        this.man = man;
    }

    @Override
    public void addComponents() {

        northPanel.add(welcome);
        centerPanel.setLayout(new GridLayout(3, 4, 20, 20));
        centerPanel.add(createFlight);
        centerPanel.add(editFlight);
        centerPanel.add(deleteFlight);
        centerPanel.add(addAirport);
        centerPanel.add(editAirport);
        centerPanel.add(deleteAirport);
        centerPanel.add(addPromotion);
        centerPanel.add(editGST);
        centerPanel.add(salesReport);
        centerPanel.add(viewUsers);
        southPanel.add(logout);
        centerPanel.setBorder(BorderFactory.createEmptyBorder(50, 100, 50, 100));

        welcome.setText("Welcome, " + man.getUsername());

        
    }

    /**
     *
     */
    public void clearGUI() {
        removeAll();
        repaint();
    }

    public void setActionListeners()
    {
        salesReport.addActionListener(new UCCtoALAdapter(new UCUIViewSalesReport()));
        createFlight.addActionListener(new UCCtoALAdapter(new UCUICreateFlight()));
        editFlight.addActionListener(new UCCtoALAdapter(new UCUIEditFlight()));
        deleteFlight.addActionListener(new UCCtoALAdapter(new UCUIDeleteFlight()));
        addAirport.addActionListener(new UCCtoALAdapter(new UCUIAddAirport()));
        editAirport.addActionListener(new UCCtoALAdapter(new UCUIEditAirport()));
        deleteAirport.addActionListener(new UCCtoALAdapter(new UCUIDeleteAirport()));
        logout.addActionListener(new UCCtoALAdapter(new UCLogout(this,man)));
        addPromotion.addActionListener(new UCCtoALAdapter(new UCUIAddPromotion()));
        editGST.addActionListener((new UCCtoALAdapter(new UCUIEditGST())));
        viewUsers.addActionListener(new UCCtoALAdapter(new UCUIClientListView(man)));
    }
}
